<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            background-color: #e5e5e5;
        }
        ul{
            width: 1200px;
            height: 600px;
            /* background-color: orange; */
            margin: 50px auto;
        }
        ul li{
            width: 234px;
            height: 300px;
            background-color: #fff;
            float: left;
            margin: 10px;
            text-align: center;
            list-style: none;
            font-size: 14px;
            padding: 20px;
            box-sizing: border-box;
        }
        ul li img{
            width: 160px;
            height: 160px;
            margin-top: 30px;
        }
        ul li p{
            line-height: 30px;
        }
        ul li .des{
            font-size: 12px;
            color: #b0b0b0;
            overflow:hidden; 
            text-overflow:ellipsis;
            display:-webkit-box; 
            -webkit-box-orient: vertical;
            -webkit-line-clamp:1; 
        }
        ul li .price{
            color: #ff6700;
        }
    </style>
</head>
<body>
    <input type="text">
    <button>查询</button>
    <ul></ul> 
    <script src="./js/cart.js"></script>
    <script>
        // 获取元素
        let ul = document.querySelector('ul')
        let input = document.querySelector('input')
        let btn = document.querySelector('button')

        // 根据数据渲染列表
        function render(data){
            // 遍历数据
            data.forEach(item=>{
                ul.innerHTML += `
                <li>
                    <img src="${item.url}" alt="">
                    <h3>${item.title}</h3>
                    <p class="des">${item.des}</p>
                    <p class="price">${item.price}元</p>
                </li>
                `
            })
        }
        render(cart)

        btn.onclick = function(){
            // 过滤，拿到新的数据
                    
            // 重新渲染
            ul.innerHTML = ''
            let newData = cart.filter(item=>{
                return item.title.includes(input.value)
            })
            //  
            render(newData) 
            // 过滤数据的地方需要把之前写死的数据改变成文本框的value
        }

        
      
    </script>
</body>
</html>